package com.anyonavinfo.cpaddemo.view.mainview.miniweather;

import android.app.Activity;
import android.content.Context;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.RelativeSizeSpan;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.LinearInterpolator;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.anyonavinfo.cpaddemo.R;
import com.anyonavinfo.cpaddemo.data.timeinfo.source.TimeInfoRepository;
import com.anyonavinfo.cpaddemo.data.weatherinfo.source.WeatherInfoRepository;

/**
 * Created by ZuiC on 2017/1/16.
 */

public class MiniWeatherView extends LinearLayout implements MiniWeatherContract.View{

    private Context mContext;
    private TextView tvTime,tvData,tvTemperature,tvWeatherType;

    public MiniWeatherView(Context context) {
        super(context);
        initView(context);
    }

    public MiniWeatherView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }

    public MiniWeatherView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }

    private void initView(Context context){
        this.mContext = context;
        LayoutInflater layoutInflater = LayoutInflater.from(mContext);
        View view = layoutInflater.inflate(R.layout.view_mainview_miniweather_miniweatherview, this);

        tvData = (TextView) view.findViewById(R.id.tv_date);
        tvTime = (TextView) view.findViewById(R.id.tv_time);
        tvTemperature = (TextView) view.findViewById(R.id.tv_temperature);
        tvWeatherType = (TextView) view.findViewById(R.id.tv_weather_type);

        new MiniWeatherPresenter(MiniWeatherView.this, TimeInfoRepository.getInstance()
        , WeatherInfoRepository.getInstance()).start();
    }

    @Override
    public void updateTime(String time) {
        tvTime.setText(time);
    }

    @Override
    public void updateDate(String date) {
        tvData.setText(date);
    }

    @Override
    public void updateTemperature(final String temp) {
        ((Activity)mContext).runOnUiThread(new Runnable() {
            @Override
            public void run() {
<<<<<<< HEAD
                tvTemperature.setText(temp );
=======
                tvTemperature.setText(temp + "°");
>>>>>>> b56716b621890f59100a220d4c7abe0ddb29e232
            }
        });
    }

    @Override
    public void updateWeatherType(final String type) {
        ((Activity)mContext).runOnUiThread(new Runnable() {
            @Override
            public void run() {
                tvWeatherType.setText(type);
            }
        });
    }

    @Override
    public void setPresenter(MiniWeatherContract.Presenter presenter) {

    }
}
